﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Data.SqlServerCe;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;


namespace SGQ.Controller
{
    class ConnectFactory : IDisposable
    {
        private SqlCeConnection sqlConnection;
        private static string strConn = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

        public ConnectFactory() {
            try
            {
                sqlConnection = new SqlCeConnection(strConn);
            }
            catch (Exception exception)
            {
                throw new Exception("An error occured while connecting to the database. See innerException for details.", exception);
            };
        }

        public SqlCeConnection CreateConnection()
        {
            try
            {
                sqlConnection.Open();
            }
            catch (Exception exception)
            {
                throw new Exception("An error occured while connecting to the database. See innerException for details.", exception);
            }
            return sqlConnection;
        }

        public void CloseConnection() {
            sqlConnection.Close();

        }

        public void Dispose() {
            CloseConnection();
        }
    }
}
